import {defineStore} from 'pinia'
import {ref} from 'vue'

// 使用setup模式定义 
export const useSetupStore = defineStore('setupStore',()=>{
  const data = ref(1)
  function getData(){
    return data.value+1
  }
  async function increment(){
    const user = await asyncFunction('rzz')
    data.value = user // 修改state
  }
  return { data,getData,increment } // 需要 return 
})

function asyncFunction(name){
  return new Promise((resolve,reject)=>{
    setTimeout(() => {
      console.log("2秒后")
      if(name!='rzz'){
        reject('错了错')
      }else{
        resolve(33) 
      }
    }, 2000);
  })
  
}
